<?php 
class Default_Model_Employee extends Zend_Db_Table_Abstract
{
	private $db = null;
	protected $_name = 'employee'; 
  	protected $_primary = 'employee_id'; 
  	const SPECAL_EP = 16;
	public function init()
	{
		$this->db = Zend_Registry::get('DB');
	}
	public function listEmployee()
	{
		$select = $this->select("employee");		
		return $select;
	}
	public function getIdAndName()
	{
		$select = $this->db->select()
					   ->from(array('e'=>'employee'),'employee_id')						  
					   ->columns("employee_name");
		$data = $this->db->query($select)->fetchAll();
		return $data;
	} 
	public function getName($id)
	{
		$select = $this->db->select()
					   ->from(array('e'=>'employee'),'employee_id')						  
					   ->columns("employee_name")
					   ->where('employee_id = ?', $id);
		$data = $this->db->query($select)->fetchAll(Zend_Db::FETCH_ASSOC);
		return $data[0]['employee_name'];	
	}
	public function addEmployee($data)
	{		
		return $this->insert($data);
	}
	public function getEmployee($id)
	{
		$result = $this->find($id)->toArray();
		return $result[0];
	}
	public function delEmployee($id)
	{
		if ( $id == self::SPECAL_EP ) return true;
		$where = $this->db->quoteInto('employee_id = ?', $id);
		return $this->delete($where);
	}
	public function updateEmployee($id,$data)
	{
		$where = $this->db->quoteInto('employee_id = ?', $id);
		return $this->update($data,$where);
	}
	
}